/**
 * Created by AllanXu on 01/03/2016.
 */
define(function (require) {
    var Vue = require('vue'),
        Config = require('config'),
        _ = require('ajax'),
        utilities = require('utilities');


    var id = utilities.getParameterByName('id');
    var qtid = sessionStorage.qtid;

    var app = new Vue({
        el: '#enroll_detail',
        data: {
            previewImg: '',
            self: {},
            mateId: '',
            showSendMsg: false,
            mainInfo: ''
        },
        methods: {
            init: function () {
                _(Config.SERVICE.MATES.ENTOLL + '?id=' + id, {}, function (data) {
                    app.mainInfo = data.obj;
                });
            },
            // 发信息
            sendMsgDialog: function (mateId2) {
                app.mateId = mateId2;
                app.showSendMsg=!app.showSendMsg;
            },
            sendMsg: function (msgContent) {
                if(qtid==null){
                    alert("您还未登录");
                    location.href = 'enroll_sign.html?id=' + app.mainInfo.blind.id;
                    return;
                }
                if (app.mateId == qtid) {
                    alert("不能发送给自己");
                } else {
                    _(Config.SERVICE.ACTIVITY.ENROLLSAYHI + '?enMsg.memberA.id=' + qtid + '&enMsg.memberB.id=' + app.mateId + '&enMsg.msg=' + msgContent, {}, function (data) {
                        if (data.code == 200) {
                            app.msgContent = '';
                            app.showSendMsg = false;
                            alert("发送成功");
                        }
                    });
                }
            },
            sh: function (partid) {
                if(qtid==null){
                    alert("您还未登录");
                    location.href = 'enroll_sign.html?id=' + app.mainInfo.blind.id;
                    return;
                }
                if(confirm("每人只有一次机会，您是否已经考虑好？")){
                    _(Config.SERVICE.ACTIVITY.ENROLLVOTE+'?id='+qtid+'&enroll.id='+partid, {}, function (data) {
                        if (data.code == 200 && data.type === 'SUCCESS') {
                            alert('献花成功！');
                            utilities.refreshUserInfo(function (data) {
                                //location.reload();
                            });
                        }else{
                            alert(data.errmsg);
                        }
                    });
                }
            }
        }
    });
    app.init();
});
